<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

define('IS_POST', \think\Request::instance()->isPost());
define('IS_GET', \think\Request::instance()->isGet());
define('IS_AJAX', \think\Request::instance()->isAjax());
define('PAGINAGE_ARTICLE',\think\Db::table('webset')->where('webset_name','=','PAGINAGE_ARTICLE')->find());
define('CATE_DISPLAY',\think\Db::table('webset')->where('webset_name','=','CATE_DISPLAY')->find());


/**
 * 将(多维)数组转换成字符串
 * @param $array
 * @return string
 */
function arrayToString($array)
{
    if (is_array($array)) {
        return implode(',', array_map('arrayToString', $array));
    }
    return $array;
}


/**
 *密码加密
 * @param $newPwd 新密码
 * @return $encipherment 加密后的密码
 */
function encrypt($newPwd)
{
    $encipherment = password_hash($newPwd, PASSWORD_BCRYPT);
    return $encipherment;
}


/**
 * 校验密码
 * @param $postPwd
 * @param $pwd
 * @return bool
 */
function passwordVerify($postPwd, $pwd)
{
    return password_verify($postPwd, $pwd);
}


function GetTree($arr, $pid=0, $step=0)
{
    global $tree;
    foreach ($arr as $key => $val) {
        if ($val['pid'] == $pid) {
            $flg1 = '';
            if ($pid){
                $flg = str_repeat("&ensp;&ensp;&ensp;", $step);
                $flg1 = $flg . "└─";
            }
            $val['cate_name'] = $flg1 . $val['cate_name'];
            $tree[] = $val;
            GetTree($arr, $val['cate_id'], $step + 1);
        }
    }
    return $tree;
}